package com.gmall.coupon.service;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class RabbitMQServive_PaySuccess {

    @RabbitHandler
    @RabbitListener(queues = "Queue_PaySuccess_Coupon")
    public void receive_30min(Channel channal, Message message,Long orderId) throws IOException {
        long deliveryTag = message.getMessageProperties().getDeliveryTag();
        try {
            //修改优惠券为已使用

            channal.basicAck(deliveryTag, false);//手动确认，告诉MQ，我收到了，你可以删掉
        }catch (Exception e){
            e.printStackTrace();
            try {
                channal.basicNack(deliveryTag,false,true);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    }

}
